package operation;

import book.BookList;

import java.util.Scanner;

public class ReturnOperation implements IOperation{
    public void work(BookList bookList){
        System.out.println("归还图书");
        System.out.println("请输入你要归还的图书名字：");
        Scanner scanner=new Scanner(System.in);
        String name=scanner.next();
        int curSize=bookList.getUsedSize();
        int i = 0;
        for (; i < curSize; i++) {
            if(bookList.getBooks(i).getName().equals(name)){

                bookList.getBooks(i).setBorrowed(false);
                System.out.println("归还成功");
                //break;
                return;
            }
        }
        if(i==curSize)//扩展：如果无此书的话如何再次重复此程序？
        {
            System.out.println("无此书");
            work(bookList);//类似于递归
        }

    }
    }

